home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / gnu / bash / bash_108 / bash-108.zoo / src / variables.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-22  |  2.3 KB  |  54 lines

  1. /* variables.h -- data structures for shell variables. */
  2.  
  3. /* Shell variables and functions are stored in hash tables. */
  4.  
  5. /* What a shell variable looks like. */
  6.  
  7. typedef struct variable *DYNAMIC_FUNC ();
  8.  
  9. typedef struct variable {
  10.   char *name;            /* Symbol that the user types. */
  11.   char *value;            /* Value that is returned. */
  12.   DYNAMIC_FUNC *dynamic_value;    /* Function called to return a `dynamic'
  13.                    value for a variable, like $SECONDS
  14.                    or $RANDOM. */
  15.   DYNAMIC_FUNC *assign_func;     /* Function called when this `special
  16.                    variable' is assigned a value in
  17.                    bind_variable. */
  18.   int attributes;        /* export, readonly, array, invisible... */
  19.   int context;            /* Which context this variable belongs to. */
  20.   struct variable *prev_context; /* Value from previous context or NULL. */
  21. } SHELL_VAR;
  22.  
  23. /* The various attributes that a given variable can have.
  24.    We only reserve one byte of the INT. */
  25. #define att_exported  0x01    /* %00000001 (export to environment) */
  26. #define att_readonly  0x02    /* %00000010 (cannot change)         */
  27. #define att_invisible 0x04    /* %00000100 (cannot see)         */
  28. #define att_array     0x08    /* %00001000 (value is an array)     */
  29. #define att_nounset   0x10    /* %00010000 (cannot unset)         */
  30. #define att_function  0x20    /* %00100000 (value is a function)   */
  31. #define att_integer   0x40    /* %01000000 (internal rep. is int)  */
  32.  
  33. #define exported_p(var)        ((((var)->attributes) & (att_exported)))
  34. #define readonly_p(var)        ((((var)->attributes) & (att_readonly)))
  35. #define invisible_p(var)    ((((var)->attributes) & (att_invisible)))
  36. #define array_p(var)        ((((var)->attributes) & (att_array)))
  37. #define function_p(var)        ((((var)->attributes) & (att_function)))
  38. #define integer_p(var)        ((((var)->attributes) & (att_integer)))
  39.  
  40. #define value_cell(var) ((var)->value)
  41. #define function_cell(var) (COMMAND *)((var)->value)
  42.  
  43. /* Stuff for hacking variables. */
  44. #include "hash.h"
  45. extern HASH_TABLE *shell_variables, *shell_functions;
  46. extern SHELL_VAR *find_function (), *find_variable (), *variable_lookup ();
  47. extern SHELL_VAR *copy_variable (), *bind_variable (), *bind_function ();
  48. extern char *get_string_value (), *dollar_vars[];
  49. extern char **export_env;
  50. extern SHELL_VAR **map_over ();
  51. extern SHELL_VAR **all_shell_variables (), **all_shell_functions ();
  52. extern int variable_in_context ();
  53. extern int variable_context;
  54.